PHP inherits the ternary operator you might now from C or Perl.

<h3>Syntax</h3>

<pre>&lt;condition> ? &lt;value on true> : &lt;value on false></pre>

<h3>Examples</h3>

Set variable $query with HTTP GET parameter q or to 'default' if parameter is missing.
<pre>
$query = isset($_GET['q'])?$_GET['q']:'default';
</pre>

Multiple defaults: the first non-false value is returned

<pre>$result = $input1 ?: $input2 ?: $input3</pre>

<h3>Use Cases</h3>

Why would you want to use the ternary operator?

<ul>
<li>Non-disruptive editing of existing code</li>
<li>Shorter than an equivalent if condition (1 instead of 5 lines)</li>
<li>If you want to output the result of the condition in 1 output method invocation</li>
<li>To use a list of variables as defaults for a result</li>
</ul>
